XF.Destin = new function() {
	
	this.addExcelDestin = function(){
		XF.lightSideBar('addExcelDestin');
		$.ajax({
			type:'post',
			url:global.contextPath + "/destin/addExcel",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#destinCenter').html(xhr);
			}
		});	
	};
	
	this.queryDestin = function(){
		XF.lightSideBar('queryDestin');
		$.ajax({
			type:'post',
			url:global.contextPath + "/destin/query",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#destinCenter').html(xhr);
			}
		});	
	};
	this.queryExcelDestin = function(){
		XF.lightSideBar('queryExcelDestin');
		$.ajax({
			type:'post',
			url:global.contextPath + "/destin/queryExcel",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#destinCenter').html(xhr);
			}
		});	
	};
	
	this.doQueryDestin = function(){
		$("#areaname").val("");
		var form = {
				prov: $("#prov").combobox("getValue"),
				city: $("#city").combobox("getValue"),
				area: $("#area").combobox("getValue"),
				address: $("#address").val(),
			};
			XF.hideError();
			$.ajax({
				type:'post',
				url:global.contextPath + "/destin/doQuery",
				dataType: 'json',
				data:form,
				success:function(result){
					if (result.status == 'OK') {
						$('#areaname').val(result.areaname);
					} else {
						XF.refreshAfterAddFaild(JSON.parse(result.errorJson));
					}
				}			
			});
		}
	
	/**
	 * 新增目的地
	 */
	this.addDestin = function(){
		XF.lightSideBar("addDestin");
		var url  = global.contextPath + "/destin/add"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#destinCenter").html(xhr);
		  }
		});
	};
	
	/**
	 * 编辑
	 */
	this.editDestin = function(id){
		var url  = global.contextPath + "/destin/edit"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {id:id},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  if (xhr.indexOf("SomeRandomString") != -1) {
				  $("#destinCenter").html(xhr);
			  } else {
				  $.messager.show({
						title:'提示',
						msg:'编辑未取消审核',
						timeout:5000,
						showType:'slide'
				  });
			  }

 
		  }
		  
		});
	};
	
	/**
	 * 添加编辑失败错误提示
	 */
	this.refreshAfterAddFaild = function(errorJson){
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		$("span[id*='errorTip']").hide();
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		}
	};
	
	/**
	 * 目的地管理
	 */
	this.listDestin = function(siteid){
		XF.lightSideBar("listDestin");
		_destin_search(null,null,null,null,null,null,siteid,null);
	}
	/**
	 * 目的地管理
	 */
	this.listAllDestin = function(){
		XF.lightSideBar("listAllDestin");
		_destin_all_search(null,null,null,null,null,null,null,null);
	}
	/**
	 * 通用调用方法
	 */
	this.listDestinSearch = function(){
		var orderByField = null;
		var orderByMode = null;
		var siteid = null;
		var city = null;
		var area = null;
		var address = null;
		var areaname = null
		var status = null;
		siteid = $("input[name=siteid]").val();
		city = $("input[name=city]").val();
		area = $("input[name=area]").val();
		address = $("input[name=address]").val();
		areaname = $("input[name=areaname]").val();
		status = $("input[name=status]:checked").val();
		if(typeof(orderByFieldReq)!='undefined' && orderByFieldReq!=""){
			orderByField = orderByFieldReq;
			var td = $("th[orderByField="+orderByField+"]");
			orderByMode = td.find("span.px").attr("orderByMode");
		}
		_destin_search(orderByField,orderByMode,city,area,address,areaname,siteid,status);
	};
	
	this.listAllDestinSearch = function(){
		var orderByField = null;
		var orderByMode = null;
		var siteid = null;
		var city = null;
		var area = null;
		var address = null;
		var areaname = null
		var status = null;
		siteid = $("input[name=siteid]").val();
		city = $("input[name=city]").val();
		area = $("input[name=area]").val();
		address = $("input[name=address]").val();
		areaname = $("input[name=areaname]").val();
		status = $("input[name=status]:checked").val();
		if(typeof(orderByFieldReq)!='undefined' && orderByFieldReq!=""){
			orderByField = orderByFieldReq;
			var td = $("th[orderByField="+orderByField+"]");
			orderByMode = td.find("span.px").attr("orderByMode");
		}
		_destin_all_search(orderByField,orderByMode,city,area,address,areaname,siteid,status);
	};
	
	this.refreshAfterDestinFaild = function(errorJson){
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		$("span[id*='errorTip']").hide();
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		} 
	};
	
	/**
     * 具体搜索方法实现
     */
    function _destin_search(orderByField,orderByMode,city,area,address,areaname,siteid,status){
    	config.destin_search['args'] = [orderByField,orderByMode,city,area,address,areaname,siteid,status];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.destin_search);
    }
    
	/**
     * 具体搜索方法实现
     */
    function _destin_all_search(orderByField,orderByMode,city,area,address,areaname,siteid,status){
    	config.destin_all_search['args'] = [orderByField,orderByMode,city,area,address,areaname,siteid,status];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.destin_all_search);
    }
    
    this.deleteDestin = function(id){
		$.messager.confirm('提示',"确认删除这条记录？",function(r){
		    if (r){
				var url  = global.contextPath + "/destin/doDelete"
				$.ajax({
				  url: url,
				  type: "post",
				  data: {id:id},
				  complete: function(xhr){
					  xhr = xhr['responseText'];
					  xhr = new Function("return " + xhr);
					  xhr = xhr();
					  xhr = xhr['status'];
					  if(xhr=="SUCCESS"){
						  $.messager.show({
							title:'提示',
							msg:'删除成功',
							timeout:3000,
							showType:'slide'
						  });
						  $(".userListWrap tr i[s="+id+"]").parent().parent().parent().remove();
					  }else if(xhr=="FAILD"){
						  $.messager.show({
							title:'提示',
							msg:'删除失败或未取消审核',
							timeout:5000,
							showType:'slide'
						  });
					  }
				   }
				});
		    }
		});
	};
	
	/**
	 * 审核-执行
	 */
	this.doAudit = function(a,id){
		var $audit = $("#audit"+id+"" ).html();
		var r = "0";
		if($audit == "审核"){			
			r = "1";
			$("#audit"+id+"" ).html("取消审核");
			$("#auditTab"+id+"" ).html("已审核");
		}else if($audit == "取消审核"){			
			r = "0";
			$("#audit"+id+"" ).html("审核");
			$("#auditTab"+id+"" ).html("未审核");
		}
		XF.lightSideBar('audit'); 
		var url  = global.contextPath + "/destin/doAudit"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {id:id,status:r,auditor:a},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  xhr = new Function("return " + xhr);
			  xhr = xhr();
			  var status = xhr['status'];
			  if("SUCCESS"==status){
				  var msg = xhr['msg'];
				  $.messager.show({
					title:'提示',
					msg:msg,
					timeout:5000,
					showType:'slide'
				  });
			  }
		  }
		});
	}
	
	
	/**
	 * 全部审核
	 */
	this.doAllAudit = function(a,siteid){		
		XF.lightSideBar('allAudit'); 
		var url  = global.contextPath + "/destin/doAllAudit"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {siteid:siteid,auditor:a},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  xhr = new Function("return " + xhr);
			  xhr = xhr();
			  var status = xhr['status'];
			  if("SUCCESS"==status){
				  var msg = xhr['msg'];
				  $.messager.show({
					title:'提示',
					msg:msg,
					timeout:5000,
					showType:'slide'
				  });
			  }
		  }
		});
	}
	/**
	 * 选取删除
	 */
	this.doSelectDelete = function(idStr,audStr,siteid){	
		var url  = global.contextPath + "/destin/doSelectDelete"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {idStr:idStr,audStr:audStr},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  xhr = new Function("return " + xhr);
			  xhr = xhr();
			  var status = xhr['status'];
			  if("SUCCESS"==status){
				  var msg = xhr['msg'];
				  $.messager.show({
					title:'提示',
					msg:msg,
					timeout:5000,
					showType:'slide'
				  });
				  if(siteid == null){
					  XF.Destin.listAllDestin(siteid) 
				  }else{
					  XF.Destin.listDestin(siteid) 
				  }
				  
			  }else{
				  var msg = xhr['msg'];
				  $.messager.show({
					title:'提示',
					msg:msg,
					timeout:5000,
					showType:'slide'
				  });
			  }
		  }
		});
	}
	
	/**
	 * 选取取消审核
	 */
	this.doSelectCancelAudit = function(auditor,idStr){	
		var url  = global.contextPath + "/destin/doSelectCancelAudit"		
		$.ajax({
		  url: url,
		  type: "post",
		  data: {auditor:auditor,idStr:idStr},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  xhr = new Function("return " + xhr);
			  xhr = xhr();
			  var status = xhr['status'];
			  if("SUCCESS"==status){
				  var msg = xhr['msg'];
				  $.messager.show({
					title:'提示',
					msg:msg,
					timeout:5000,
					showType:'slide'
				  });
			  }
		  }
		});
	}
	
	/**
	 * 选取审核
	 */
	this.doSelectAudit = function(auditor,idStr){	
		var url  = global.contextPath + "/destin/doSelectAudit"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {auditor:auditor,idStr:idStr},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  xhr = new Function("return " + xhr);
			  xhr = xhr();
			  var status = xhr['status'];
			  if("SUCCESS"==status){
				  var msg = xhr['msg'];
				  $.messager.show({
					title:'提示',
					msg:msg,
					timeout:5000,
					showType:'slide'
				  });
			  }
		  }
		});
	}
	
}
config.destin_search = {
		url: ""+global.contextPath+"/destin/list",
	    argsOrder: ['orderByField','orderByMode','city','area','address','areaname','siteid','status'],
	    needVar: true,
	    replaceExp: '#destinCenter',
	    callBack: function() {
	    }		
};
config.destin_all_search = {
		url: ""+global.contextPath+"/destin/listAll",
	    argsOrder: ['orderByField','orderByMode','city','area','address','areaname','siteid','status'],
	    needVar: true,
	    replaceExp: '#destinCenter',
	    callBack: function() {
	    }		
};